{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Jupyter 三大优点\n",
    "\n",
    "## 1、整合所有的资源\n",
    "\n",
    "你可以看文档的同时运行代码，而无需像 IDE 那样切换多个窗口。\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "?json.dumps"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2、交互性编程体验\n",
    "\n",
    "一个程序，可以分成多个部分，修改某个部分，不需要全部都重新运行，大大提高效率。而且与终端深度融合，不需要再单独打开一个 cmd 或终端窗口。\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "sum = 0\n",
    "for i in range(1000): #模拟耗时\n",
    "    sum += i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "359640.0"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sum *= 0.9\n",
    "sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "mkdir: /Users/aaron/tmp/编程小妙招: File exists\n",
      "total 24\n",
      "drwxr-xr-x  15 aaron  staff  480  1 29 08:39 \u001b[1m\u001b[36melectron-quick-start\u001b[m\u001b[m\n",
      "drwxr-xr-x   6 aaron  staff  192  1 26 22:00 \u001b[1m\u001b[36menv\u001b[m\u001b[m\n",
      "drwxr-xr-x   4 aaron  staff  128  1 29 13:45 \u001b[1m\u001b[36mhello-world\u001b[m\u001b[m\n",
      "drwxr-xr-x   4 aaron  staff  128  1 28 15:33 \u001b[1m\u001b[36mmy-electron-app\u001b[m\u001b[m\n",
      "drwxr-xr-x   3 aaron  staff   96  1 29 09:16 \u001b[1m\u001b[36mnode_modules\u001b[m\u001b[m\n",
      "-rw-r--r--   1 aaron  staff   10  1 27 06:26 requirements.in\n",
      "-rw-r--r--   1 aaron  staff  164  1 27 06:28 requirements.txt\n",
      "drwxr-xr-x   3 aaron  staff   96  1 25 07:13 \u001b[1m\u001b[36mrsa\u001b[m\u001b[m\n",
      "drwxr-xr-x  13 aaron  staff  416  1 27 09:42 \u001b[1m\u001b[36mstack\u001b[m\u001b[m\n",
      "drwxr-xr-x   8 aaron  staff  256  2 22 08:49 \u001b[1m\u001b[36mtmdb\u001b[m\u001b[m\n",
      "-rw-r--r--   1 aaron  staff   86  1 29 09:16 yarn.lock\n",
      "drwxr-xr-x   2 aaron  staff   64  2 23 22:40 \u001b[1m\u001b[36m编程小妙招\u001b[m\u001b[m\n"
     ]
    }
   ],
   "source": [
    "#使用 shell 或者 cmd 命令 \n",
    "name = \"编程小妙招\"\n",
    "!mkdir ~/tmp/$name\n",
    "!ls -l ~/tmp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: https://pypi.doubanio.com/simple/\n",
      "Collecting somedecorators\n",
      "  Downloading https://pypi.doubanio.com/packages/a9/b8/6e03419024acaf0f73cc59aa4d82c11010460a4019b8a5d103b752921b0c/somedecorators-0.7-py3-none-any.whl (9.0 kB)\n",
      "Collecting djangomail\n",
      "  Downloading https://pypi.doubanio.com/packages/de/be/f379cdcb04e7684b9e72cc7d3bc38509d3ea4adf2eb64a5662a089f188f7/djangomail-0.5-py3-none-any.whl (74 kB)\n",
      "\u001b[K     |████████████████████████████████| 74 kB 790 kB/s eta 0:00:011\n",
      "\u001b[?25hInstalling collected packages: djangomail, somedecorators\n",
      "Successfully installed djangomail-0.5 somedecorators-0.7\n",
      "\u001b[33mWARNING: You are using pip version 21.2.4; however, version 22.0.3 is available.\n",
      "You should consider upgrading via the '/Users/aaron/py310env/bin/python3 -m pip install --upgrade pip' command.\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!pip install somedecorators"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3、零成本重现结果\n",
    "\n",
    "把 url 发布出来，别人就能运行你的代码，完全不需要再安装一遍依赖。你也可以直接把ijupyter notebook 文件直接发布到 GitHub，别人可以直接看到代码的结果，而不需要运行。\n",
    "\n",
    "https://github.com/binder-examples/python2_with_3/blob/master/index3.ipynb\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 949 µs, sys: 1.53 ms, total: 2.48 ms\n",
      "Wall time: 2 s\n"
     ]
    }
   ],
   "source": [
    "%time import time;time.sleep(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "CPU times: user 1.14 ms, sys: 1.4 ms, total: 2.54 ms\n",
      "Wall time: 2 s\n"
     ]
    }
   ],
   "source": [
    "%%time \n",
    "import time\n",
    "time.sleep(2)\n",
    "print(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "46.4 ns ± 0.48 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%timeit x = [1,2,3,4,5,6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "235 ns ± 17.1 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%%timeit \n",
    "x = [1,2,3,4,5,6]\n",
    "sum = 0\n",
    "for i in x:\n",
    "    sum += i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "import json\n",
      "?json.dumps\n",
      "sum = 0\n",
      "for i in range(1000): #模拟耗时\n",
      "    sum += i\n",
      "sum *= 0.8\n",
      "sum\n",
      "sum *= 0.9\n",
      "sum\n",
      "#使用 shell 或者 cmd 命令 \n",
      "name = \"编程小妙招\"\n",
      "!mkdir ~/tmp/$name\n",
      "!ls -l ~/tmp\n",
      "!pip install somedecorators\n",
      "%time import time;time.sleep(2)\n",
      "%%time \n",
      "import time\n",
      "time.sleep(2)\n",
      "print(2)\n",
      "%timeit x = [1,2,3,4,5,6]\n",
      "%hist\n"
     ]
    }
   ],
   "source": [
    "%hist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Automatic pdb calling has been turned ON\n"
     ]
    }
   ],
   "source": [
    "%pdb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "division.py              python-dict-vs-set.md    字符串.ipynb\r\n",
      "etl-pandas.md            python-install.md        未命名.ipynb\r\n",
      "jupyter-tutorial.md      python-list-vs-tuple.md  字典与集合.ipynb\r\n",
      "jupyter.ipynb            python-roadmap.md\r\n",
      "mp.md                    数字.ipynb\r\n"
     ]
    }
   ],
   "source": [
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "import sys\r\n",
      "def fun(a,b):\r\n",
      "    '''\r\n",
      "    计算两个数的商\r\n",
      "    '''\r\n",
      "    print(f\"{a = }\")\r\n",
      "    print(f\"{b = }\")\r\n",
      "    val = a/b\r\n",
      "    print(f\"a/b = {val}\")\r\n",
      "\r\n",
      "\r\n",
      "if __name__ == \"__main__\":\r\n",
      "    fun(int(sys.argv[1]),int(sys.argv[2]))\r\n"
     ]
    }
   ],
   "source": [
    "cat division.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a = 1\n",
      "b = 3\n",
      "a/b = 0.3333333333333333\n"
     ]
    }
   ],
   "source": [
    "%run division.py 1 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Breakpoint 1 at /Users/aaron/github/somenzz/push_blog/docs/blog/2022/02/division.py:1\n",
      "NOTE: Enter 'c' at the ipdb>  prompt to continue execution.\n",
      "> \u001b[0;32m/Users/aaron/github/somenzz/push_blog/docs/blog/2022/02/division.py\u001b[0m(1)\u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n",
      "\u001b[1;31m1\u001b[0;32m---> 1 \u001b[0;31m\u001b[0;32mimport\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m      2 \u001b[0;31m\u001b[0;32mdef\u001b[0m \u001b[0mfun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m      3 \u001b[0;31m    '''\n",
      "\u001b[0m\u001b[0;32m      4 \u001b[0;31m    \u001b[0m计算两个数的商\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m      5 \u001b[0;31m    '''\n",
      "\u001b[0m\n",
      "ipdb> ?\n",
      "Object `` not found.\n",
      "ipdb> help\n",
      "\n",
      "Documented commands (type help <topic>):\n",
      "========================================\n",
      "EOF    commands   enable    ll        pp       s                until \n",
      "a      condition  exit      longlist  psource  skip_hidden      up    \n",
      "alias  cont       h         n         q        skip_predicates  w     \n",
      "args   context    help      next      quit     source           whatis\n",
      "b      continue   ignore    p         r        step             where \n",
      "break  d          interact  pdef      restart  tbreak         \n",
      "bt     debug      j         pdoc      return   u              \n",
      "c      disable    jump      pfile     retval   unalias        \n",
      "cl     display    l         pinfo     run      undisplay      \n",
      "clear  down       list      pinfo2    rv       unt            \n",
      "\n",
      "Miscellaneous help topics:\n",
      "==========================\n",
      "exec  pdb\n",
      "\n",
      "ipdb> help s\n",
      "s(tep)\n",
      "        Execute the current line, stop at the first possible occasion\n",
      "        (either in a function that is called or in the current\n",
      "        function).\n",
      "ipdb> s\n",
      "> \u001b[0;32m/Users/aaron/github/somenzz/push_blog/docs/blog/2022/02/division.py\u001b[0m(2)\u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n",
      "\u001b[1;31m1\u001b[0;32m     1 \u001b[0;31m\u001b[0;32mimport\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m----> 2 \u001b[0;31m\u001b[0;32mdef\u001b[0m \u001b[0mfun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m      3 \u001b[0;31m    '''\n",
      "\u001b[0m\u001b[0;32m      4 \u001b[0;31m    \u001b[0m计算两个数的商\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m      5 \u001b[0;31m    '''\n",
      "\u001b[0m\n",
      "ipdb> s\n",
      "> \u001b[0;32m/Users/aaron/github/somenzz/push_blog/docs/blog/2022/02/division.py\u001b[0m(12)\u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;32m      9 \u001b[0;31m    \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"a/b = {val}\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m     10 \u001b[0;31m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m     11 \u001b[0;31m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m---> 12 \u001b[0;31m\u001b[0;32mif\u001b[0m \u001b[0m__name__\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m\"__main__\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m     13 \u001b[0;31m    \u001b[0mfun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0margv\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0margv\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\n",
      "ipdb> s\n",
      "> \u001b[0;32m/Users/aaron/github/somenzz/push_blog/docs/blog/2022/02/division.py\u001b[0m(13)\u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;32m      9 \u001b[0;31m    \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"a/b = {val}\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m     10 \u001b[0;31m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m     11 \u001b[0;31m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m     12 \u001b[0;31m\u001b[0;32mif\u001b[0m \u001b[0m__name__\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m\"__main__\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m---> 13 \u001b[0;31m    \u001b[0mfun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0margv\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0margv\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\n",
      "ipdb> s\n",
      "--Call--\n",
      "> \u001b[0;32m/Users/aaron/github/somenzz/push_blog/docs/blog/2022/02/division.py\u001b[0m(2)\u001b[0;36mfun\u001b[0;34m()\u001b[0m\n",
      "\u001b[1;31m1\u001b[0;32m     1 \u001b[0;31m\u001b[0;32mimport\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m----> 2 \u001b[0;31m\u001b[0;32mdef\u001b[0m \u001b[0mfun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m      3 \u001b[0;31m    '''\n",
      "\u001b[0m\u001b[0;32m      4 \u001b[0;31m    \u001b[0m计算两个数的商\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m      5 \u001b[0;31m    '''\n",
      "\u001b[0m\n",
      "ipdb> s\n",
      "> \u001b[0;32m/Users/aaron/github/somenzz/push_blog/docs/blog/2022/02/division.py\u001b[0m(6)\u001b[0;36mfun\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;32m      4 \u001b[0;31m    \u001b[0m计算两个数的商\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m      5 \u001b[0;31m    '''\n",
      "\u001b[0m\u001b[0;32m----> 6 \u001b[0;31m    \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"{a = }\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m      7 \u001b[0;31m    \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"{b = }\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m      8 \u001b[0;31m    \u001b[0mval\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\n",
      "ipdb> s\n",
      "--Call--\n",
      "> \u001b[0;32m/Users/aaron/py310env/lib/python3.10/site-packages/ipykernel/iostream.py\u001b[0m(502)\u001b[0;36mwrite\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;32m    500 \u001b[0;31m                parent=self.parent_header, ident=self.topic)\n",
      "\u001b[0m\u001b[0;32m    501 \u001b[0;31m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m--> 502 \u001b[0;31m    \u001b[0;32mdef\u001b[0m \u001b[0mwrite\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstring\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m    503 \u001b[0;31m        \"\"\"Write to current stream after encoding if necessary\n",
      "\u001b[0m\u001b[0;32m    504 \u001b[0;31m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\n",
      "ipdb> help b\n",
      "b(reak) [ ([filename:]lineno | function) [, condition] ]\n",
      "        Without argument, list all breaks.\n",
      "\n",
      "        With a line number argument, set a break at this line in the\n",
      "        current file.  With a function name, set a break at the first\n",
      "        executable line of that function.  If a second argument is\n",
      "        present, it is a string specifying an expression which must\n",
      "        evaluate to true before the breakpoint is honored.\n",
      "\n",
      "        The line number may be prefixed with a filename and a colon,\n",
      "        to specify a breakpoint in another file (probably one that\n",
      "        hasn't been loaded yet).  The file is searched for on\n",
      "        sys.path; the .py suffix may be omitted.\n",
      "ipdb> b 8\n",
      "Breakpoint 2 at /Users/aaron/py310env/lib/python3.10/site-packages/ipykernel/iostream.py:8\n",
      "ipdb> help c\n",
      "c(ont(inue))\n",
      "        Continue execution, only stop when a breakpoint is encountered.\n",
      "ipdb> c\n",
      "a = 1\n",
      "b = 0\n",
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n",
      "\u001b[0;31mZeroDivisionError\u001b[0m                         Traceback (most recent call last)\n",
      "File \u001b[0;32m~/py310env/lib/python3.10/site-packages/IPython/core/interactiveshell.py:2632\u001b[0m, in \u001b[0;36mInteractiveShell.safe_execfile\u001b[0;34m(self, fname, exit_ignore, raise_exceptions, shell_futures, *where)\u001b[0m\n",
      "\u001b[1;32m   2630\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n",
      "\u001b[1;32m   2631\u001b[0m     glob, loc \u001b[38;5;241m=\u001b[39m (where \u001b[38;5;241m+\u001b[39m (\u001b[38;5;28;01mNone\u001b[39;00m, ))[:\u001b[38;5;241m2\u001b[39m]\n",
      "\u001b[0;32m-> 2632\u001b[0m     \u001b[43mpy3compat\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mexecfile\u001b[49m\u001b[43m(\u001b[49m\n",
      "\u001b[1;32m   2633\u001b[0m \u001b[43m        \u001b[49m\u001b[43mfname\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mglob\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mloc\u001b[49m\u001b[43m,\u001b[49m\n",
      "\u001b[1;32m   2634\u001b[0m \u001b[43m        \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcompile\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mshell_futures\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m)\u001b[49m\n",
      "\u001b[1;32m   2635\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mSystemExit\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m status:\n",
      "\u001b[1;32m   2636\u001b[0m     \u001b[38;5;66;03m# If the call was made with 0 or None exit status (sys.exit(0)\u001b[39;00m\n",
      "\u001b[1;32m   2637\u001b[0m     \u001b[38;5;66;03m# or sys.exit() ), don't bother showing a traceback, as both of\u001b[39;00m\n",
      "\u001b[0;32m   (...)\u001b[0m\n",
      "\u001b[1;32m   2643\u001b[0m     \u001b[38;5;66;03m# For other exit status, we show the exception unless\u001b[39;00m\n",
      "\u001b[1;32m   2644\u001b[0m     \u001b[38;5;66;03m# explicitly silenced, but only in short form.\u001b[39;00m\n",
      "\u001b[1;32m   2645\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m status\u001b[38;5;241m.\u001b[39mcode:\n",
      "\n",
      "File \u001b[0;32m~/py310env/lib/python3.10/site-packages/IPython/utils/py3compat.py:55\u001b[0m, in \u001b[0;36mexecfile\u001b[0;34m(fname, glob, loc, compiler)\u001b[0m\n",
      "\u001b[1;32m     53\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mopen\u001b[39m(fname, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrb\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mas\u001b[39;00m f:\n",
      "\u001b[1;32m     54\u001b[0m     compiler \u001b[38;5;241m=\u001b[39m compiler \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mcompile\u001b[39m\n",
      "\u001b[0;32m---> 55\u001b[0m     \u001b[43mexec\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcompiler\u001b[49m\u001b[43m(\u001b[49m\u001b[43mf\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mread\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfname\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mexec\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mglob\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mloc\u001b[49m\u001b[43m)\u001b[49m\n",
      "\n",
      "File \u001b[0;32m~/github/somenzz/push_blog/docs/blog/2022/02/division.py:13\u001b[0m, in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n",
      "\u001b[1;32m      9\u001b[0m     \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124ma/b = \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mval\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n",
      "\u001b[1;32m     12\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;18m__name__\u001b[39m \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m__main__\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n",
      "\u001b[0;32m---> 13\u001b[0m     \u001b[43mfun\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43msys\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43margv\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43msys\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43margv\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n",
      "\n",
      "File \u001b[0;32m~/github/somenzz/push_blog/docs/blog/2022/02/division.py:8\u001b[0m, in \u001b[0;36mfun\u001b[0;34m(a, b)\u001b[0m\n",
      "\u001b[1;32m      6\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00ma \u001b[38;5;132;01m= }\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n",
      "\u001b[1;32m      7\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mb \u001b[38;5;132;01m= }\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n",
      "\u001b[0;32m----> 8\u001b[0m val \u001b[38;5;241m=\u001b[39m \u001b[43ma\u001b[49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[43mb\u001b[49m\n",
      "\u001b[1;32m      9\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124ma/b = \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mval\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n",
      "\n",
      "\u001b[0;31mZeroDivisionError\u001b[0m: division by zero\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "> \u001b[0;32m/Users/aaron/github/somenzz/push_blog/docs/blog/2022/02/division.py\u001b[0m(8)\u001b[0;36mfun\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;32m      6 \u001b[0;31m    \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"{a = }\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m      7 \u001b[0;31m    \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"{b = }\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m----> 8 \u001b[0;31m    \u001b[0mval\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m      9 \u001b[0;31m    \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"a/b = {val}\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m     10 \u001b[0;31m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\n",
      "ipdb> help l\n",
      "Print lines of code from the current stack frame\n",
      "ipdb> l\n",
      "\u001b[1;32m      3 \u001b[0m    '''\n",
      "\u001b[1;32m      4 \u001b[0m    \u001b[0m计算两个数的商\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m      5 \u001b[0m    '''\n",
      "\u001b[1;32m      6 \u001b[0m    \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"{a = }\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m      7 \u001b[0m    \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"{b = }\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m----> 8 \u001b[0;31m    \u001b[0mval\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[1;32m      9 \u001b[0m    \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"a/b = {val}\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m     10 \u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m     11 \u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m     12 \u001b[0m\u001b[0;32mif\u001b[0m \u001b[0m__name__\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m\"__main__\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m     13 \u001b[0m    \u001b[0mfun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0margv\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0margv\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\n",
      "ipdb> help\n",
      "\n",
      "Documented commands (type help <topic>):\n",
      "========================================\n",
      "EOF    commands   enable    ll        pp       s                until \n",
      "a      condition  exit      longlist  psource  skip_hidden      up    \n",
      "alias  cont       h         n         q        skip_predicates  w     \n",
      "args   context    help      next      quit     source           whatis\n",
      "b      continue   ignore    p         r        step             where \n",
      "break  d          interact  pdef      restart  tbreak         \n",
      "bt     debug      j         pdoc      return   u              \n",
      "c      disable    jump      pfile     retval   unalias        \n",
      "cl     display    l         pinfo     run      undisplay      \n",
      "clear  down       list      pinfo2    rv       unt            \n",
      "\n",
      "Miscellaneous help topics:\n",
      "==========================\n",
      "exec  pdb\n",
      "\n",
      "ipdb> a\n",
      "a = 1\n",
      "b = 0\n",
      "ipdb> s\n"
     ]
    }
   ],
   "source": [
    "%run -d division.py 1 0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 学习资料\n",
    "\n",
    "\n",
    "- Jupyter 官方：\n",
    "\n",
    "[https://mybinder.org/v2/gh/binder-examples/matplotlib-versions/mpl-v2.0/?filepath=matplotlib_versions_demo.ipynb](https://mybinder.org/v2/gh/binder-examples/matplotlib-versions/mpl-v2.0/?filepath=matplotlib_versions_demo.ipynb)    \n",
    "- Google Research 提供的 Colab 环境，尤其适合机器学习的实践应用\n",
    "\n",
    "[https://colab.research.google.com/notebooks/basic_features_overview.ipynb](https://colab.research.google.com/notebooks/basic_features_overview.ipynb)\n",
    "\n",
    "- 如果你想在本地或者远程的机器上安装 Jupyter Notebook，可以参考下面的两个文档:\n",
    " - 安装：[https://jupyter.org/install.html](https://jupyter.org/install.html)\n",
    " - 运行：[https://jupyter.readthedocs.io/en/latest/running.html#running总结](https://jupyter.readthedocs.io/en/latest/running.html#running总结)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
